import { defineStore } from "pinia";

interface AppInfoState {
  title: string;
  logo: string;
  description: string;
  version: string;
}

interface AppState {
  collapsed: boolean;
  isDark: boolean;
  info: AppInfoState;
  tabs: AppTab[];
  currentTab: string | null;
}

export interface AppTab {
  name: string;
  label: string;
  key: string;
  favico: () => Function | string;
}

export const useAppStore = defineStore("app", {
  state: (): AppState => ({
    collapsed: false,
    isDark: false,
    info: {
      logo: "",
      title: import.meta.env["VITE_TITLE"],
      description: "",
      version: "",
    },
    tabs: [],
    currentTab: null,
  }),
  actions: {
    switchCollapsed() {
      this.collapsed = !this.collapsed;
    },
    setCollapsed(b: boolean) {
      this.collapsed = b;
    },
    setTabs(tabs: AppTab[]) {
      this.tabs = tabs;
    },
    setCurrentTab(tab: string) {
      this.currentTab = tab;
    },
  },
  persist: {
    paths: ["app"],
    storage: sessionStorage,
  },
});
